package com.wxn.learncompose.widget

import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

/***
 * 去掉 点击产生的水波纹效果的 IconButton
 * IconButton 的源码中其实将 Box 里的 modifier.clickable 参数 Indication 设置成波纹了
 */
@Composable
fun NoRipperIconButton(
    onClick: () ->Unit,
    modifier :Modifier = Modifier,
    enable: Boolean = true,
    interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
    content : @Composable () -> Unit
) {

    val iconButtonSizeModifier = Modifier.size(48.dp)
    Box(
        modifier = modifier.clickable(
            onClick = onClick,
            enabled = enable,
            interactionSource = interactionSource,
            // 去掉水波纹，将indication 设置为null就行了
            indication = null, //原始IconButton的indication = rememberRipple(bounded = false, radius = RippleRadius),
        ).then(iconButtonSizeModifier),
        contentAlignment = Alignment.Center
    ) {
        content()
    }

}